//============================================================================================
/**
 * @file	phclink_diary.c
 * @brief	ＰＨＣ−ＤＳ接続画面 送信デモ画面 【シーケンス】
 * @author	Akito Mori
 * @date	09.02.02
 */
//============================================================================================
#include "common.h"
#include "gflib/touchpanel.h"
#include "system/gamedata.h"
#include "system/procsys.h"
#include "system/main.h"
#include "system/fontproc.h"
#include "system/window.h"
#include "system/pmfprint.h"
#include "system/snd_tool.h"
#include "system/arc_tool.h"
#include "system/arc_util.h"
#include "system/clact_tool.h"
#include "system/clact_util.h"
#include "system/msgdata.h"
#include "system/wordset.h"
#include "system/mystatus.h"
#include "system/wipe.h"
#include "savedata/config.h"
#include "itemtool/item.h"
#include "itemtool/myitem.h"
#include "msgdata/msg.naix"

#include "application/phclink.h"
#include "phclink_obj_def.h"
#include "phclink_bmp_def.h"
#include "phclink_local.h"
#include "phclink_obj.h"
#include "phclink_bmp.h"
#include "phc_ds.naix"

// 有効にするとPHC日記のバージョンワークを金銀に書き換える
//#define DEBUG_DIARY_VERSION


enum{
	SUBSEQ_ERROR_MSG=0,
	SUBSEQ_ERROR_WAIT,
	SUBSEQ_ERROR_END,
};




///< PHC日記呼び出し用PROCデータ
static const PROC_DATA PhcDiaryProcData = {
	PhcDiaryProc_Init,
	PhcDiaryProc_Main,
	PhcDiaryProc_End,
	NO_OVERLAY_ID,
};


//==============================================================================
/**
 * @brief   PHC日記呼び出しアプリ初期化
 *
 * @param   wk		PHC画面ワーク
 *
 * @retval  アプリシーケンス
 */
//==============================================================================
int PhcLink_SeqDiary_Init( PHCLINK_WORK *wk )
{
	OS_Printf("PhcLink_SeqDiary_Init\n");

//	PhcLinkBmp_Exit( wk, PL_BMP_PAGE_B );		// BMPウィンドウ開放
//	PhcLinkBmp_Exit( wk, PL_BMP_PAGE_A );		// BMPウィンドウ開放


#ifdef DEBUG_DIARY_VERSION
	{
		int i;
		for(i=0;i<24;i++){
			wk->phcsys.Data.diary[i].romVersion = VERSION_GOLD;
		}
	}
#endif

	wk->phcsys.diary_param.pSaveData  = wk->savedata;
	wk->phcsys.diary_param.pDiaryData = wk->phcsys.Data.diary;

	{
		int i;
		for(i=0;i<24;i++){
			PHCDiary *d = &wk->phcsys.Data.diary[i];
			OS_Printf("--------------------\n");
			OS_Printf("actionID = %d, enemyNumber=%d, pokeNumber=%d\n", d->actionId,d->enemyNumber,d->pokeNumber);
			OS_Printf("courseId = %d, itemNumber=%d, friendly=%d\n", d->courseId,d->itemNumber,d->friendly);
		}
	}

	WIPE_SYS_Start(
		WIPE_PATTERN_WMS, WIPE_TYPE_FADEOUT, WIPE_TYPE_FADEOUT,
		WIPE_FADE_WHITE, WIPE_DEF_DIV, WIPE_DEF_SYNC, HEAPID_PHC_LINK );

	Snd_BgmFadeOut( 0, 16 );

	return SEQ_MAINSEQ_MAIN;
}

//==============================================================================
/**
 * @brief   ＰＨＣ日記呼び出しアプリメイン
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  アプリシーケンス
 */
//==============================================================================
int PhcLink_SeqDiary_Main( PHCLINK_WORK *wk )
{
	switch(wk->subseq){
	case 0:
		if( WIPE_SYS_EndCheck() == TRUE ){
			// ＰＨＣ接続画面リソース全解放
			PhcLink_ResourceExit( wk );
			// エラーページチェック
			if( PhcDiary_CheckErrorPage( wk->phcsys.Data.diary ) )
			{
				// エラーページがあった場合は日記に遷移しない
				return SEQ_MAINSEQ_END;
			}
			wk->subseq = 1;
		}
		break;
	case 1:
		// サブプロセス開始
		wk->proc = PROC_Create( &PhcDiaryProcData,  &wk->phcsys.diary_param, HEAPID_PHC_LINK);
		wk->subseq = 2;
		break;
	case 2:
		if(ProcMain(wk->proc)){
			// PROC解放
			PROC_Delete( wk->proc );
			wk->subseq = 3;
		}
		break;
	case 3:
		return SEQ_MAINSEQ_END;
		break;


	}
	return SEQ_MAINSEQ_MAIN;
}
//==============================================================================
/**
 * @brief   PHC日記呼び出しアプリ終了
 *
 * @param   wk	PHC画面ワーク
 *
 * @retval  アプリシーケンス
 */
//==============================================================================
int PhcLink_SeqDiary_End( PHCLINK_WORK *wk )
{
	// ＰＨＣ接続画面リソース再初期化
	PhcLink_ResourceInit( wk );

//	PhcLinkBmp_Init( wk, PL_BMP_PAGE_A );		// BMPウィンドウ確保
//	PhcLinkBmp_Init( wk, PL_BMP_PAGE_B );		// BMPウィンドウ確保


	OS_Printf("PhcLink_SeqDiary_End\n");

//	wk->mainseq_next = MAINSEQ_START;
	wk->subseq = 0;
	wk->mainseq_next = MAINSEQ_BENEFIT;
	return SEQ_MAINSEQ_INIT;
}
